.\"     Title: IPSEC_TTOUL
.\"    Author: 
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\"      Date: 11/14/2008
.\"    Manual: 16 Aug 2000
.\"    Source: 16 Aug 2000
.\"
.TH "IPSEC_TTOUL" "3" "11/14/2008" "16 Aug 2000" "16 Aug 2000"
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
ipsec_ttoul, ipsec_ultot - convert unsigned-long numbers to and from text
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <freeswan\.h>

.fi
.ft
.HP 18
.BI "const char *ttoul(const\ char\ *\ " "src" ", size_t\ " "srclen" ", int\ " "base" ", unsigned\ long\ *\ " "n" ");"
.sp
.ft B
.nf

.fi
.ft
.HP 13
.BI "size_t ultot(unsigned\ long\ " "n" ", int\ " "format" ", char\ *\ " "dst" ", size_t\ " "dstlen" ");"
.SH "DESCRIPTION"
.PP
\fITtoul\fR
converts a text\-string number into a binary
\fBunsigned long\fR
value\.
\fIUltot\fR
does the reverse conversion, back to a text version\.
.PP
Numbers are specified in text as decimal (e\.g\.
123), octal with a leading zero (e\.g\.
012, which has value 10), or hexadecimal with a leading
\fB0x\fR
(e\.g\.
\fB0x1f\fR, which has value 31) in either upper or lower case\.
.PP
The
\fIsrclen\fR
parameter of
\fBttoul\fR
specifies the length of the string pointed to by
\fIsrc\fR; it is an error for there to be anything else (e\.g\., a terminating NUL) within that length\. As a convenience for cases where an entire NUL\-terminated string is to be converted, a
\fIsrclen\fR
value of
0
is taken to mean
\fBstrlen(src)\fR\.
.PP
The
\fIbase\fR
parameter of
\fBttoul\fR
can be
8,
10, or
16, in which case the number supplied is assumed to be of that form (and in the case of
16, to lack any
\fB0x\fR
prefix)\. It can also be
0, in which case the number is examined for a leading zero or a leading
\fB0x\fR
to determine its base\.
.PP
The
\fIdstlen\fR
parameter of
\fBultot\fR
specifies the size of the
\fIdst\fR
parameter; under no circumstances are more than
\fIdstlen\fR
bytes written to
\fIdst\fR\. A result which will not fit is truncated\.
\fIDstlen\fR
can be zero, in which case
\fIdst\fR
need not be valid and no result is written, but the return value is unaffected; in all other cases, the (possibly truncated) result is NUL\-terminated\. The
\fIfreeswan\.h\fR
header file defines a constant,
\fBULTOT_BUF\fR, which is the size of a buffer just large enough for worst\-case results\.
.PP
The
\fIformat\fR
parameter of
\fBultot\fR
must be one of:
.PP
\fB\'o\'\fR
.RS 4
octal conversion with leading
0
.RE
.PP
\fB\ 8\fR
.RS 4
octal conversion with no leading
0
.RE
.PP
\fB\'d\'\fR
.RS 4
decimal conversion
.RE
.PP
10
.RS 4
same as
\fBd\fR
.RE
.PP
\fB\'x\'\fR
.RS 4
hexadecimal conversion, including leading
\fB0x\fR
.RE
.PP
16
.RS 4
hexadecimal conversion with no leading
\fB0x\fR
.RE
.PP
17
.RS 4
like
16
except padded on left with
0s to eight digits (full width of a 32\-bit number)
.RE
.PP
\fITtoul\fR
returns NULL for success and a pointer to a string\-literal error message for failure; see DIAGNOSTICS\.
\fIUltot\fR
returns
0
for a failure, and otherwise returns the size of buffer which would be needed to accommodate the full conversion result, including terminating NUL (it is the caller\'s responsibility to check this against the size of the provided buffer to determine whether truncation has occurred)\.
.SH "SEE ALSO"
.PP
\fBatol\fR(3),
\fBstrtoul\fR(3)
.SH "DIAGNOSTICS"
.PP
Fatal errors in
\fBttoul\fR
are: empty input; unknown
\fIbase\fR; non\-digit character found; number too large for an
\fBunsigned long\fR\.
.PP
Fatal errors in
\fBultot\fR
are: unknown
\fIformat\fR\.
.SH "HISTORY"
.PP
Written for the FreeS/WAN project by Henry Spencer\.
.SH "BUGS"
.PP
Conversion of
0
with format
\fBo\fR
yields
00\.
.PP
\fIUltot\fR
format
17
is a bit of a kludge\.
.PP
The restriction of error reports to literal strings (so that callers don\'t need to worry about freeing them or copying them) does limit the precision of error reporting\.
.PP
The error\-reporting convention lends itself to slightly obscure code, because many readers will not think of NULL as signifying success\. A good way to make it clearer is to write something like:
.sp
.RS 4
.nf
\fBconst char *error;\fR

\fBerror = ttoul( /* \.\.\. */ );\fR
\fBif (error != NULL) {\fR
\fB        /* something went wrong */\fR
.fi
.RE
.sp
